{% extends 'generic/object.html' %}
{% load helpers %}
{% load plugins %}
{% load render_table from django_tables2 %}

{% block breadcrumbs %}
  {{ block.super }}
  {% if object.vrf %}
    <li class="breadcrumb-item"><a href="{% url 'ipam:ipaddress_list' %}?vrf_id={{ object.vrf.pk }}">{{ object.vrf }}</a></li>
  {% endif %}
{% endblock %}

{% block content %}
<div class="row">
	<div class="col col-md-4">
      <div class="card">
          <h5 class="card-header">
              IP Address
          </h5>
          <div class="card-body">
              <table class="table table-hover attr-table">
                  <tr>
                      <th scope="row">Family</th>
                      <td>IPv{{ object.family }}</td>
                  </tr>
                  <tr>
                      <th scope="row">VRF</th>
                      <td>
                          {% if object.vrf %}
                              <a href="{% url 'ipam:vrf' pk=object.vrf.pk %}">{{ object.vrf }}</a>
                          {% else %}
                              <span>Global</span>
                          {% endif %}
                      </td>
                  </tr>
                  <tr>
                      <th scope="row">Tenant</th>
                      <td>
                          {% if object.tenant %}
                              {% if object.tenant.group %}
                                  <a href="{{ object.tenant.group.get_absolute_url }}">{{ object.tenant.group }}</a> /
                              {% endif %}
                              <a href="{{ object.tenant.get_absolute_url }}">{{ object.tenant }}</a>
                          {% else %}
                              <span class="text-muted">None</span>
                          {% endif %}
                      </td>
                  </tr>
                  <tr>
                      <th scope="row">Status</th>
                      <td>
                          <span class="badge bg-{{ object.get_status_class }}">{{ object.get_status_display }}</span>
                      </td>
                  </tr>
                  <tr>
                      <th scope="row">Role</th>
                      <td>
                          {% if object.role %}
                              <a href="{% url 'ipam:ipaddress_list' %}?role={{ object.role }}">{{ object.get_role_display }}</a>
                          {% else %}
                              <span class="text-muted">None</span>
                          {% endif %}
                      </td>
                  </tr>
                  <tr>
                      <th scope="row">DNS Name</th>
                      <td>{{ object.dns_name|placeholder }}</td>
                  </tr>
                  <tr>
                      <th scope="row">Description</th>
                      <td>{{ object.description|placeholder }}</td>
                  </tr>
                  <tr>
                      <th scope="row">Assignment</th>
                      <td>
                        {% if object.assigned_object %}
                          {% if object.assigned_object.parent_object %}
                            <a href="{{ object.assigned_object.parent_object.get_absolute_url }}">{{ object.assigned_object.parent_object }}</a> /
                          {% endif %}
                          <a href="{{ object.assigned_object.get_absolute_url }}">{{ object.assigned_object }}
                        {% else %}
                          <span class="text-muted">&mdash;</span>
                        {% endif %}
                      </td>
                  </tr>
                  <tr>
                      <th scope="row">NAT (inside)</th>
                      <td>
                          {% if object.nat_inside %}
                              <a href="{{ object.nat_inside.get_absolute_url }}">{{ object.nat_inside }}</a>
                              {% if object.nat_inside.assigned_object %}
                                  (<a href="{{ object.nat_inside.assigned_object.parent_object.get_absolute_url }}">{{ object.nat_inside.assigned_object.parent_object }}</a>)
                              {% endif %}
                          {% else %}
                              <span class="text-muted">None</span>
                          {% endif %}
                      </td>
                  </tr>
                  <tr>
                      <th scope="row">NAT (outside)</th>
                      <td>
                          {% if object.nat_outside %}
                              <a href="{{ object.nat_outside.get_absolute_url }}">{{ object.nat_outside }}</a>
                          {% else %}
                              <span class="text-muted">None</span>
                          {% endif %}
                      </td>
                  </tr>
              </table>
          </div>
      </div>
      {% include 'inc/panels/tags.html' %}
      {% include 'inc/panels/custom_fields.html' %}
      {% plugin_left_page object %}
	</div>
	<div class="col col-md-8">
    {% include 'inc/panel_table.html' with table=parent_prefixes_table heading='Parent Prefixes' %}
    {% if duplicate_ips_table.rows %}
        {# Custom version of panel_table.html #}
        <div class="card border-danger">
            <h5 class="card-header">
              <span class="text-danger">Duplicate IP Addresses</span>
                {% if more_duplicate_ips %}
                  <div class="float-end">
                    <a type="button" class="btn btn-primary btn-sm"
                    {% if object.vrf %}
                    href="{% url 'ipam:ipaddress_list' %}?address={{ object.address.ip }}&vrf_id={{ object.vrf.pk }}"
                    {% else %}
                    href="{% url 'ipam:ipaddress_list' %}?address={{ object.address.ip }}&vrf_id=null"
                    {% endif %}
                    >Show all</a>
                  </div>
                {% endif %}
            </h5>
            <div class="card-body table-responsive">
              {% render_table duplicate_ips_table 'inc/table.html' %}
            </div>
        </div>
    {% endif %}
    <div class="my-3">
      {% include 'inc/panel_table.html' with table=related_ips_table heading='Related IP Addresses' %}
    </div>
    {% plugin_right_page object %}
	</div>
</div>

<div class="row">
    <div class="col col-md-12">
        {% plugin_full_width_page object %}
    </div>
</div>
{% endblock %}
